package de.hfu.android;

import java.util.List;

import de.hfu.helper.DataAccess;
import de.hfu.model.DayPlan;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.os.AsyncTask;

public class UpdateFromTheInternetTask extends AsyncTask<Void, Void, Void> implements OnCancelListener{
	Context context;
	ProgressDialog dialog;
	WeekViewListManager listViewManager;
	
	@Override
	protected void onPreExecute() {
		String content = context.getResources().getString(R.string.loading);
		dialog = ProgressDialog.show(context, "", content, true, true);
		dialog.setOnCancelListener(this);
	}
	
	public UpdateFromTheInternetTask(Context context, WeekViewListManager listViewManager) {
		this.context = context;
		this.listViewManager = listViewManager;
	}
	
	@Override
	protected Void doInBackground(Void... params) {
		DataAccess dac = DataAccess.getInstance(context);
		dac.updateFromTheInternet();
		return null;
	}
	
	@Override
	protected void onPostExecute(Void result) {
		dialog.dismiss();
		listViewManager.reloadData();
	}
	
	@Override
	public void onCancel(DialogInterface dialog) {
		this.cancel(true);
		listViewManager.reloadData();
	}

}
